package com.autulin.gb28181library;

import android.util.Log;

import com.autulin.gb28181library.utils.JNIBridgeInterface;

public class JNIBridge {
    static {
        System.loadLibrary("exosip");
        System.loadLibrary("gb_native");
    }

    public static JNIBridgeInterface jNIBridgeInterface;

    public final static int ROTATE_0_CROP_LF = 0;
    /**
     * 旋转90度剪裁左上
     */
    public final static int ROTATE_90_CROP_LT = 1;
    /**
     * 暂时没处理
     */
    public final static int ROTATE_180 = 2;
    /**
     * 旋转270(-90)裁剪左上，左右镜像
     */
    public final static int ROTATE_270_CROP_LT_MIRROR_LR = 3;


    public final static int UDP = 0;
    public final static int TCP = 1;
    public static final int FILE = 2;


    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public static native String stringFromJNI();

    public static native String getFFmpegConfig();

    /**
     * @param ip            服务器ip
     * @param remotePort    端口
     * @param localPort     端口
     * @param outType       tcp/udp/file
     * @param mediaBasePath 视频存放目录
     * @param mediaName     视频名称
     * @param filter        旋转镜像剪切处理
     * @param in_width      输入视频宽度
     * @param in_height     输入视频高度
     * @param out_height    输出视频高度
     * @param out_width     输出视频宽度
     * @param frameRate     视频帧率
     * @param bit_rate      视频比特率
     * @param audioFrameLen 音频长度
     * @return
     */
    public static native int initMuxer(
            String ip,
            int remotePort,
            int localPort,
            int outType,
            String mediaBasePath,
            String mediaName,
            int filter,
            int in_width,
            int in_height,
            int out_width,
            int out_height,
            int frameRate,
            long bit_rate,
            int audioFrameLen,
            int ssrc,
            int queue_max
    );

    public static native int sendOneVideoFrame(byte[] data);

    public static native int sendOneAudioFrame(byte[] data);

    public static native int endMux();

    public static native void RegisterFromJNI(String server_ip,String server_port,String server_id,String user_id,String user_password,String ipc_ip);

    public static native void StopRegisterListning();


    public static void jni_callback(String message) {
        Log.i("JNI_CALLBACK","message="+message);
        if(jNIBridgeInterface!=null){
            jNIBridgeInterface.jniCallBack(message);
       }
    }

}
